#include "Stdafx.h"

#include "RenderDevice.h"

namespace WindGE
{
	RenderDevice::RenderDevice()
		: device_(nullptr)
		, immediate_context_(nullptr)
	{
	}

	RenderDevice::~RenderDevice()
	{
		safe_release(device_);

		if (immediate_context_) immediate_context_->ClearState();
		safe_release(immediate_context_);
	}

	bool RenderDevice::init(RenderDeviceDesc deviceParam)
	{
		D3D_FEATURE_LEVEL featureLevel;
		HRESULT hr = D3D11CreateDevice(
			nullptr,					//default dxgi adapter
			deviceParam.dirverType,
			0,
			deviceParam.deviceFlags,
			0,
			0,
			D3D11_SDK_VERSION,
			&device_,
			&featureLevel,
			&immediate_context_);

		if (FAILED(hr))
		{
			//XdPrint("Create render device failed !");
			return false;
		}

		if (featureLevel != D3D_FEATURE_LEVEL_11_0)
		{
			//XdPrint("Device not support D3D_11_0");
			return false;
		}

		return true;
	}

}//end namespace WindGE

